#include "Config.hpp"
#include <boost/program_options.hpp>

namespace po = boost::program_options;

namespace netspy
{

Config::Config()
{
	setDefaultValues();
}


void Config::parseCommandLine(int argc, char *argv[]) throw (int)
{
	po::options_description desc("Available options");
	desc.add_options()
    		("help", "prints this help")
    		("interval", po::value<unsigned int>(), "sets interval time (should be given in seconds)")
		("verbose", "sets verbose mode -> server printouts everything he can  ")
		("port",po::value<unsigned int>(), "changes registration port (default = 5000) ")
	
	;

	po::variables_map vm;
	po::store(po::parse_command_line(argc, argv, desc), vm);
	po::notify(vm);    

	if (vm.count("help")) 
	{
		std::cout << desc << "\n";
	   	throw 0;
	}

	if (vm.count("interval")) 
	{
		checkPeriod_ =  vm["interval"].as<unsigned int>();
	}
	
	if (vm.count("verbose"))
	{
		isVerbose_=true;
	}

	if(vm.count("port"))
	{
		registerPort_ = vm["port"].as<unsigned int>();
	}
		
}

void Config::setDefaultValues()
{
	checkPeriod_ 		= defaultCheckPeriod;
	registerPort_		= defaultRegisterPort;
	isVerbose_		= defaultVerbose;
	checkerThreadNumber_	= defaultCheckerThreadNumber;
        databaseName_ = defaultDatabaseName();
        databaseUser_ = defaultDatabaseUser();
        databasePass_ = defaultDatabasePass();
}


bool Config::isVerbose() const {
	return isVerbose_;
}

uint32_t Config::getCheckPeriod() const {
	return checkPeriod_;
}

uint16_t Config::getRegisterPort() const {
	return registerPort_;
}

const char * Config::getDatabaseName() const{
    return databaseName_;
}

const char * Config::getDatabasePass() const {
    return databasePass_;
}

const char * Config::getDatabaseUser() const {
    return databaseUser_;
}
uint32_t Config::getCheckerThreadNumber() const
{
	return checkerThreadNumber_;
}

}

